import {DisplaySuccessMessage, DisplayWarnMessage, RemoveMessage} from "./Action";
import {MessageType} from "./MessageType";

const initialMessage = {
  messageType: MessageType.NoMessage,
  message: null,
};

export const onMessage = (state = initialMessage, action) => {
  switch (action.type) {
    case DisplayWarnMessage: {
      return {...action.param, messageType: MessageType.Warning}
    }
    case DisplaySuccessMessage: {
      return {...action.param, messageType: MessageType.Success}
    }
    case RemoveMessage: {
      return initialMessage;
    }
  }
  return state;
};